<!-- 其他入库结算 -->
<template>
  <div class="mod-config">
    <el-button-group style="margin-bottom: 10px;">
      <el-button icon="el-icon-search" type="primary" @click="searchHandle">查询</el-button>
      <el-button icon="el-icon-delete" type="primary" @click="searchReset">清空</el-button>
    </el-button-group>
          <el-form inline label-width="100px" @keyup.enter.native="searchHandle">
            <el-form-item label="单据编号">
              <el-input v-model="dataForm.billId"></el-input>
            </el-form-item>
            <el-form-item label="结算人">
              <el-input v-model="dataForm.financeUserName"></el-input>
            </el-form-item>
            <el-form-item label="制造商">
              <el-input v-model="dataForm.supplyName" v-if="!dataForm.id">
                <el-button slot="append" @click="openDialog('supply')">选择</el-button>
              </el-input>
              <el-select v-model="dataForm.supplyId" v-if="dataForm.id" disabled>
                <el-option v-for="item in supplyOptions" :value="item.id" :label="item.name" :key="item.id"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="入库仓位">
              <el-select size="mini" v-model="dataForm.inStockId" clearable>
                <el-option v-for="item in stockOptions" :value="item.id" :label="item.name" :key="item.id"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="审核状态">
              <el-select v-model="dataForm.inveStatus" placeholder="请选择"  clearable>
                <el-option v-for="item in inveStatusOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="商品名称">
              <el-input v-model="dataForm.goodsName"></el-input>
            </el-form-item>
            <el-form-item label="审核日期">
              <el-row>
                <el-col :span="11">
                  <el-date-picker style="width: 100%;" v-model="dataForm.financeTimeStart" value-format="yyyy-MM-dd" type="date" placeholder="选择日期"></el-date-picker>
                </el-col>
                <el-col :span="2" style="text-align: center;">至</el-col>
                <el-col :span="11">
                  <el-date-picker style="width: 100%;" v-model="dataForm.financeTimeEnd" type="date" value-format="yyyy-MM-dd" placeholder="选择日期"></el-date-picker>
                </el-col>
              </el-row>
            </el-form-item>
          </el-form>

      <div class="avue-crud">
        <el-table :data="dataList" border v-loading="dataListLoading" :max-height="tableHeight">
          <el-table-column label="操作" width="180" fixed="right">
            <template slot-scope="scope">
              <el-button type="text" icon="el-icon-search" @click="showDetails(scope.row.id)">详情</el-button>
              <el-button v-if="permissions.eims_takeinventory_edit" type="text" icon="el-icon-edit" @click="addOrUpdateHandle(scope.row.id)" :disabled="scope.row.inveStatus == '2'">修改</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="billId" label="单据编号" width="190"></el-table-column>
          <el-table-column prop="inStockName" label="入库仓位" minwidth="140"></el-table-column>
          <el-table-column prop="inveType" label="入库类型" width="140" :formatter="inveTypeFormatter"></el-table-column>
          <el-table-column prop="createTime" label="单据日期" width="140"></el-table-column>
          <el-table-column prop="auditTime" label="入库日期" width="140"></el-table-column>
          <el-table-column prop="financeUserName" label="结算人" width="80"></el-table-column>
          <el-table-column prop="financeTime" label="结算日期" width="80"></el-table-column>
        </el-table>
      </div>
      <div class="avue-crud__pagination">
        <el-pagination
          @size-change="sizeChangeHandle"
          @current-change="currentChangeHandle"
          :current-page="pageIndex"
          :page-sizes="[10, 20, 50, 100, 200]"
          :page-size="pageSize"
          :total="totalPage"
          background
          layout="total, sizes, prev, pager, next"
        ></el-pagination>
      </div>
      <!-- 弹窗, 详情 -->
      <detail-table v-if="detailsVisible" ref="details" @refreshDataList="getDataList"></detail-table>
      <!-- 弹窗, 新增 / 修改 -->
      <add-table v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-table>
      <search-supply v-if="supplyVisible" ref="supplyDialog" @refreshData="getSupplyId"></search-supply>
  </div>
</template>

<script>
import { filterParams } from "@/util/tools"
import { getOtherSettlementPage } from "@/api/eims/purchase/other-warehouse"
import detailTable from "./details"
import AddTable from "./add"
import { getStockList } from "@/api/eims/stock"
import { getDeptInfo } from "@/api/admin/dept"
import { mapGetters } from "vuex"
  import SearchSupply from '@/components/business/SearchSupply'

export default {
  data() {
    return {
      printUrl: "",
      dataForm: {
        billId: '',
        financeUserName: '',
        inStockId: '',
        supplyName: "",
        brandName: "",
      },
      dataList: [],
      stockOptions: [],
      inveStatusOptions: [
        { label: "已审核", value: "2" },
        { label: "未审核", value: "1" },
      ],
      receptionDeptOptions: [],
      pageIndex: 1,
      pageSize: 200,
      totalPage: 0,
      dataListLoading: false,
      detailsVisible: false,
      supplyVisible: false,
      brandVisible: false,
      addOrUpdateVisible: false,
    };
  },
  created() {
    this.getDataList()
    this.stockList()
    this.getDeptList()
  },
  computed: {
    ...mapGetters(["permissions", "bizData"]),
    tableHeight: function(){
      return window.innerHeight - 260
    }
  },
  components: {
    detailTable,
    AddTable,
    SearchSupply
  },
  methods: {
    //  查询数据
    searchHandle() {
      this.pageIndex = 1
      this.getDataList()
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true
      let params1 = filterParams(this.dataForm)
      let params2 = { current: this.pageIndex, size: this.pageSize }
      getOtherSettlementPage(Object.assign(params2, params1)).then(response => {
        if(response.data.code == '0'){
          this.dataList = response.data.data.records
          this.totalPage = response.data.data.total
        }else{
          this.$message.error(response.data.msg)
        }
        this.dataListLoading = false
      })
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataList()
    },
    // 新增 / 修改
    addOrUpdateHandle(id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    },
    // //审核
    // audit(id) {
    //   this.$confirm("是否审核ID为" + id, "提示", {
    //     confirmButtonText: "确定",
    //     cancelButtonText: "取消",
    //     type: "warning",
    //   })
    //     .then(function () {
    //       return auditRecipientsOfOutbound(id);
    //     })
    //     .then((data) => {
    //       this.$message.success("审核成功");
    //       this.getDataList();
    //     });
    // },
    // 删除
    deleteHandle(id) {
      this.$confirm("是否确认删除ID为" + id, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(function () {
        return delObj(id)
      }).then(response => {
        if(response.data.code == '0'){
          this.$message.success("删除成功")
          this.getDataList()
        }else{
          this.$message.error(response.data.msg)
        }
      })
    },
    // 查看详情
    showDetails(id) {
      this.detailsVisible = true;
      this.$nextTick(() => {
        this.$refs.details.init(id);
      });
    },
    //  获取仓位列表
    stockList() {
      getStockList().then(response => {
        if(response.data.code == '0'){
          this.stockOptions = result.data.data
        }else{
          this.$message.error(response.data.msg)
        }
      })
    },
    getDeptList() {
      getDeptInfo().then(response => {
        if(response.data.code == '0'){
          this.receptionDeptOptions = response.data.data
        }else{
          this.$message.error(response.data.msg)
        }
      })
    },
    //清空查询列表
    searchReset() {
      for (let key in this.dataForm) {
        this.dataForm[key] = "";
      }
    },
    inveTypeFormatter(row, column, cellValue, index) {
      switch (cellValue) {
        case 'OTI':
          return "其他入库";
          break;
        case 'PIN':
          return "采购入库";
          break;
      }
    },
    //获取制造商
      openDialog() {
        let data = { ctgId: 7 }
        this.supplyVisible = true
        this.$nextTick(() => {
          this.$refs.supplyDialog.init(data)
        })
      },
      getSupplyId(data) {
        this.$set(this.dataForm,'supplyName',data.name)
        this.dataForm.supplyId = data.id
      },
  },
};
</script>
